AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
--include('entities/base_wire_entity/init.lua')
include( 'shared.lua' )

function ENT:Initialize()

	self.Entity:SetModel( "models/GIMP/ammo_cannonbomb.mdl" )
	self.Entity:SetName("Powderball")
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	
	--self.Entity:SetMaterial("spacebuild/Body4")
    	
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableGravity(true)
		phys:EnableDrag(true)
		phys:EnableCollisions(true)
		phys:SetMass( 200 )
	end
	
	self.FuseTime = .5
	self.LTT = 0
end

function ENT:SpawnFunction( ply, tr )

	if ( !tr.Hit ) then return end
	
	local SpawnPos = tr.HitPos + tr.HitNormal * 16 + Vector(0,0,50)
	
	local ent = ents.Create( "Powderball" )
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	ent.SPL = ply
	
	return ent
	
end

function ENT:OnTakeDamage( info )
	self.Triggered = true
end

function ENT:Use( activator, caller )
	
end

function ENT:Touch( ent )
	
end

function ENT:Think()
	delta = CurTime() - self.LTT
	
	if self.Triggered then
		self.FuseTime = self.FuseTime - delta
	end
	
	if self.FuseTime <= 0 then
		self:Splode()
	end
	
	self.LTT = CurTime()
end

function ENT:Splode()
	util.BlastDamage(self.Entity, self.Entity, self:GetPos(), 100, 100)
	local effectdata = EffectData()
	effectdata:SetOrigin(self:GetPos())
	effectdata:SetStart(self:GetPos())
	util.Effect( "explosion", effectdata )
	self:Remove()
end